const userList = [{
	username: 'admin',
	password: 'admin',
	role: 'admin'
}, {
	username: 'common',
	password: 'common',
	role: 'common'
}]
const JWT = require('jsonwebtoken')
const bodyParser = require('body-parser')
const { list } = require('./mock')
module.exports = app => {
	app.use(bodyParser.json())

	app.post('/api/login', (req, res) => {
		const { username, password } = req.body;
		const result = userList.find(v => v.username === username && v.password === password)
		if (result) {
			res.send({
				code: 200,
				data: {
					role: result.role,
					token: JWT.sign({ role: 'admin' }, '666666')
				}
			})
		} else {
			res.send({
				code: 403
			})
		}
	})


	app.get('/api/list', (req, res) => {
		res.send({
			code: 200,
			data: list
		})
	})

}